import type {App} from "vue";

// 不工作，将覆盖原始类型
declare module 'vue' {
    interface ComponentCustomProperties {
        $translate: (key: string) => string
    }
}

export default {
    //插件中的 Provide / Inject
    // install: (app: App,option:any) => {
    //     app.provide('i18n',option)
    // }

    install(app: App<Element>, options: any) {
        app.config.globalProperties.$translate = (key: string) => {
            //$translate(x.y.z)
            //1、option[x]
            //2、option[x][y]
            //3、.....
            return key.split('.').reduce((prev: any, cur: string) => {
                if (prev && prev[cur] !== undefined) {
                    return prev[cur];
                } else {
                    return key;
                }
            }, options)
        };
    }
}